package com.genntii.examManager.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.genntii.examManager.domain.entity.CourseRecord;
import org.apache.ibatis.annotations.*;

import java.util.ArrayList;

@Mapper
public interface CourseRecordMapper extends BaseMapper<CourseRecord> {

    @Select("select count(*) from course_record where course_id = #{courseId}")
    Integer studentPartInCount(@Param("courseId")Long courseId);

    @Select("select count(*) from course_record where course_id = #{courseId} and user_id = #{userId}")
    Byte isPartIn(@Param("courseId") Long courseId, @Param("userId") Long userId);

    ArrayList<CourseRecord> isPartInBatch(ArrayList<Long> courseIds, Long userId);

    @Select("select user_id from course_record where course_id = #{courseId}")
    ArrayList<Long> getUserIdsByCourse(@Param("courseId")Long courseId);

    ArrayList<Long> getUserIdsPageByCourse(@Param("courseId") Long courseId,
                                           @Param("pageNum")Integer pageNum,
                                           @Param("pageSize")Integer pageSize,
                                           String sortOrder,
                                           String sortField);

    @Select("select count(*) from course_record where course_id = #{courseId}")
    long getUserCountByCourse(@Param("courseId")Long courseId);

    @Select("select course_id from course_record where user_id = #{userId}")
    ArrayList<Long> getCourseIdsByUserId(@Param("userId")Long userId);

    @Select("select count(*) from course_record where user_id = #{userId}")
    long getCourseCountByUserId(@Param("userId") Long userId);

    @Delete("delete from exam_manager.course_record " +
            "where exam_manager.course_record.user_id = #{userId} and " +
            "exam_manager.course_record.course_id = #{courseId}")
    void expel(Long courseId, Long userId);
}
